﻿using System;
using System.ComponentModel;
using System.Globalization;
using System.Xml.Serialization;

namespace Microsoft.WowAddonStudio.FrameXml.Serialization
{
    [Serializable]
    [DesignerCategory("code")]
    [XmlType(AnonymousType = true, Namespace = "http://www.blizzard.com/wow/ui/")]
    public class UiScript : SerializationObject
    {
        /// <summary>
        /// Gets or sets the Lua script file to be included.
        /// </summary>
        [XmlAttribute("file")]
		[Description("This refers to a file used by element, path is relative to scheme path: if addon is in \"MyAddon\" folder file specified \"myfile.lua\" will be searched in this folder (i guess only, needs testing). \"\\Interface\\Wherever\" seems to be the same as \"Interface\\Wherever\" (\"C:\\{{WoW}}\\Interface\\Wherever\").")]
        public string File { get; set; }

        /// <summary>
        /// Gets or sets the value of the <see cref="UiScript"/>.
        /// </summary>
        [XmlText]
        public string ScriptBlock { get; set; }

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        public override string ToString()
        {
            if (!String.IsNullOrEmpty(File))
				return String.Format(CultureInfo.InvariantCulture, "{{{0}}}", File);

            if (!String.IsNullOrEmpty(ScriptBlock))
                return "{ScriptBlock}";

            return "{Script}";
        }
    }
}